package com.waves.chat.controller;


import com.waves.chat.domain.dto.admin.AdminAddDTO;
import com.waves.chat.domain.dto.admin.AdminRevokeDTO;
import com.waves.chat.domain.dto.chat.ChatMessageMemberDTO;
import com.waves.chat.domain.dto.chat.GroupAddDTO;
import com.waves.chat.domain.dto.member.MemberAddDTO;
import com.waves.chat.domain.dto.member.MemberDTO;
import com.waves.chat.domain.dto.member.MemberDelDTO;
import com.waves.chat.domain.dto.member.MemberExitDTO;
import com.waves.chat.domain.vo.ChatMemberListVO;
import com.waves.chat.domain.vo.MemberVO;
import com.waves.chat.service.IGroupMemberService;
import com.waves.chat.service.RoomAppService;
import com.waves.common.domain.vo.IdReqVO;
import com.waves.common.domain.vo.IdRespVO;
import com.waves.core.utils.LoginUtils;
import com.waves.core.web.domain.R;
import com.waves.core.web.domain.vo.CursorPageBaseVO;
import com.waves.user.domain.vo.ws.ChatMemberVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 房间相关接口
 * </p>
 *
 * @author dlw
 * @since 2024-03-19
 */
@RestController
@RequestMapping("/userApi/room")
@Api(tags = "房间相关接口")
@Slf4j
public class RoomController {
    @Resource
    private RoomAppService roomService;
    @Resource
    private IGroupMemberService groupMemberService;

    @GetMapping("/public/group")
    @ApiOperation("群组详情")
    public R<MemberVO> groupDetail(@Valid IdReqVO dto) {
        return R.ok(roomService.getGroupDetail(dto.getId()));
    }

    @GetMapping("/public/group/member/page")
    @ApiOperation("群成员列表")
    public R<CursorPageBaseVO<ChatMemberVO>> getMemberPage(@Valid MemberDTO dto) {
        return R.ok(roomService.getMemberPage(dto));
    }

    @GetMapping("/group/member/list")
    @ApiOperation("房间内的所有群成员列表-@专用")
    public R<List<ChatMemberListVO>> getMemberList(@Valid ChatMessageMemberDTO dto) {
        return R.ok(roomService.getMemberList(dto));
    }

    @DeleteMapping("/group/member")
    @ApiOperation("移除成员")
    public R<Void> delMember(@Valid @RequestBody MemberDelDTO dto) {
        roomService.delMember(dto);
        return R.ok();
    }

    @DeleteMapping("/group/member/exit")
    @ApiOperation("退出群聊")
    public R<Boolean> exitGroup(@Valid @RequestBody MemberExitDTO dto) {
        groupMemberService.exitGroup(dto);
        return R.ok();
    }

    @PostMapping("/group")
    @ApiOperation("新增群组")
    public R<IdRespVO> addGroup(@Valid @RequestBody GroupAddDTO dto) {
        Long roomId = roomService.addGroup(dto);
        return R.ok(IdRespVO.id(roomId));
    }

    @PostMapping("/group/member")
    @ApiOperation("邀请好友")
    public R<Void> addMember(@Valid @RequestBody MemberAddDTO dto) {
        roomService.addMember(dto);
        return R.ok();
    }

    @PutMapping("/group/admin")
    @ApiOperation("添加管理员")
    public R<Boolean> addAdmin(@Valid @RequestBody AdminAddDTO dto) {
        groupMemberService.addAdmin(dto);
        return R.ok();
    }

    @DeleteMapping("/group/admin")
    @ApiOperation("撤销管理员")
    public R<Boolean> revokeAdmin(@Valid @RequestBody AdminRevokeDTO dto) {
        groupMemberService.revokeAdmin( dto);
        return R.ok();
    }
}
